package DTO;

import java.util.ArrayList;

import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import database.DatabaseHelper;

public class VehicleDTO {
	private String ID;
	private String Name;

	public String getID() { return ID; }
	public void setID(String iD) { ID = iD; }
	
	public String getName() { return Name; }
	public void setName(String name) { Name = name; }
	
	public static ArrayList<VehicleDTO> getAll(Context context){
		ArrayList<VehicleDTO> result = new ArrayList<VehicleDTO>();
		DatabaseHelper myDbHelper = DatabaseHelper.getInstance(context);
	 	try {
	 		myDbHelper.openDatabase();
	 	}catch(SQLException sqle){
	 		throw sqle;
	 	}
	 	String query = "SELECT * FROM Vehicles";
	 	Cursor cursor = myDbHelper.getMyDataBase().rawQuery(query, null);
		if(cursor.moveToFirst()){
			//Set value to properties
			do{
				VehicleDTO vehicleDTO = new VehicleDTO();
				vehicleDTO.setID(cursor.getString(cursor.getColumnIndex("ID")));
				vehicleDTO.setName(cursor.getString(cursor.getColumnIndex("Name")));
				result.add(vehicleDTO);
			}while(cursor.moveToNext());
		}
	 	myDbHelper.close();
	 	return result;
	}
	
}
